define(["jquery", "easy-admin", "selectBox", "ivs", "videojs", "videojsflash"], function ($, ea, selectBox, Ivs, videojs ) {
    let form = layui.form;
    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'picture.pictures/index',
        add_url: 'picture.pictures/add',
        edit_url: 'picture.pictures/edit',
        delete_url: 'picture.pictures/delete',
        export_url: 'picture.pictures/export',
        modify_url: 'picture.pictures/modify',
        monitor_url: 'picture.pictures/monitor',
    };
    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                modifyReload: true,
                toolbar: ['refresh','add','delete', [{
                    text: '监控',
                    url: init.monitor_url,
                    method: 'open',
                    auth: 'add',
                    class: 'layui-btn layui-btn-warning layui-btn-sm',
                    icon: 'fa fa-eye ',
                    extend: 'data-full="true"',
                }],],
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: 'ID', search: false},
                    {field: 'title', title: '名称'},
                    {field: 'infomation', title: '介绍', search: false},
                    {field: 'url_small', title: '大图', search: false, templet: ea.table.image},
                    {field: 'url_big', title: '小图', search: false, templet: ea.table.image},
                    {field: 'create_time', title: '创建日期', search: 'range'},
                    {width: 250, title: '操作', templet: ea.table.tool},
                ]],
            });

            ea.listen();
        },
        add: async function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
        monitor: async function() {
//             player = videojs('example_video_1',{
//                 techOrder: [ "flash", "html5", ],
//                 loop: false,
//                 autoplay: false,
//             }, function onPlayerReady() {
//                 videojs.log('Your player is ready!');
//                 this.on('ended', function() {
//                     videojs.log('Awww...over so soon?!');
//                 });
//             });

            // videojs.getPlayers()['my-video'].ready(function () {
            //     videojs.log("播放开始了2!");
            //     console.log("isFullscreen", myPlayer.isFullscreen());
            // });

            // form.on('submit(login)', async function({ field:{ account, pwd }}){
            //     let {code, msg, data:{ jssesionId = ''}} = await ivs.login(account, pwd);
            //     if(code!==200){
            //         return ivs.alert(msg);
            //     }
            //     ivs.jssesionId = jssesionId;
            //     $('button[lay-filter="login"]').text('重新登陆');
            //     ivs.success('登陆成功');
            //     return false;
            // });
            // form.on('submit(deviceList)', async function(){
            //     ivs.clearAll();
            //     let {code, msg, data} = await ivs.getDeviceList();
            //     if(code!==200){
            //         return ivs.alert(msg);
            //     }
            //     ivs.deviceList = data;
            //     ivs.getTreeData().renderTree();
            //     return false;
            // });
            // form.on('submit(logout)', async function(){
            //     let {code, msg, data} = await ivs.startDeviceLive('860301100061044',1, new Date().getTime());
            //     if(code!==200){
            //         return ivs.alert(msg);
            //     }
            //     player.src({ type: "rtmp/flv", src: data.svr.url });
            //     player.play();
            //     return false;
            // });

            let ivs = new Ivs();
            // console.log('init ivs', ivs);
            let { data:{ jssesionId = ''}} = await ivs.login($('input[name="account"]').val(), $('input[name="pwd"]').val());
            ivs.jssesionId = jssesionId;
            ivs.clearAll();
            await ivs.getDeviceList();
            ivs.renderSplitButton();

        }
    };
    return Controller;
});